package com.example.smart_city_0829.activity.sdkm;

import android.content.Context;
import android.content.Intent;
import android.os.Bundle;

import androidx.fragment.app.Fragment;

import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.CheckBox;
import android.widget.ImageView;
import android.widget.ListView;
import android.widget.TextView;

import com.example.smart_city_0829.DeathData;
import com.example.smart_city_0829.R;
import com.example.smart_city_0829.base.BaseFragment;
import com.example.smart_city_0829.base.CommonAdapter;
import com.example.smart_city_0829.entity.sdkm.Content;

public class XxbjFragment extends BaseFragment {

    private Button add;
    private ListView lv;


    @Override
    protected int getLayoutId() {
        return R.layout.fragment_xxbj;
    }

    @Override
    protected void initView() {
        add = (Button) rootView.findViewById(R.id.add);
        lv = (ListView) rootView.findViewById(R.id.lv);
    }

    @Override
    protected void initData() {
        lv.setAdapter(new CommonAdapter<Content, CommonAdapter.CommentListViewHolder>(
                DeathData.xxbj,
                requireContext()
        ) {
            @Override
            protected void setData(Content data, int position, CommentListViewHolder viewHolder, View convertView, Context context) {
                viewHolder.cb.setVisibility(View.GONE);

                viewHolder.name.setText(data.getTitle());
                viewHolder.content.setText(data.getContent());
            }

            @Override
            protected CommentListViewHolder getViewHolder() {
                return new CommentListViewHolder();
            }

            @Override
            protected void initView(CommentListViewHolder viewHolder, View convertView) {
                viewHolder.im = (ImageView) convertView.findViewById(R.id.im);
                viewHolder.name = (TextView) convertView.findViewById(R.id.name);
                viewHolder.content = (TextView) convertView.findViewById(R.id.content);
                viewHolder.tag1 = (TextView) convertView.findViewById(R.id.tag1);
                viewHolder.cb = (CheckBox) convertView.findViewById(R.id.cb);
            }

            @Override
            protected int getItemLayoutResourceId() {
                return R.layout.comment_list_item;
            }
        });
    }

    @Override
    protected void initEvent() {
        add.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent = new Intent(requireContext(),AddContentActivity.class);
                intent.putExtra("type",1);
                startActivity(intent);
            }
        });
    }

    @Override
    public void onResume() {
        super.onResume();
        initData();
    }

    @Override
    public boolean getUserVisibleHint() {
        if (super.getUserVisibleHint()){
            initData();
        }
        return super.getUserVisibleHint();
    }
}